package com.hotleproject.controller;

import com.hotleproject.pojo.Comment;
import com.hotleproject.pojo.Hotle;
import com.hotleproject.pojo.Room;
import com.hotleproject.service.HotleService;
import com.hotleproject.service.RoomService;
import com.hotleproject.service.SingleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/users")
public class SingleController {

    @Autowired
    private SingleService singleService;

    @RequestMapping("/singleDeal")
    public String findUserAll( Model model,HttpSession session,HttpServletRequest request) {
//        model.addAttribute("hotlrname",model.getAttribute("hotlename"));
        if(session.getAttribute("users")==null)
            return "please";
        String hotlename=request.getParameter("hotlename");
        String roomFaci=this.singleService.findRoomFaci();
        model.addAttribute("roomFaci", roomFaci);
        List<Room> Roomlist = this.singleService.findAllRoom();
        model.addAttribute("roomlist", Roomlist);
        Hotle Hotlelist = this.singleService.findAllHotle(hotlename);
        model.addAttribute("hotlelist", Hotlelist);
        String users=session.getAttribute("users").toString();
        model.addAttribute("users",users);

        List<Comment> commentlist = this.singleService.findComment(hotlename);

        Comment Nullcommentlist = this.singleService.findNullComment();
        if (commentlist != null) {
            model.addAttribute("commentlist", commentlist);
            return "HotleSingle";
        } else {
            model.addAttribute("commentlist", Nullcommentlist);
            return "HotleSingle";
        }

    }

    @RequestMapping("/ToSingleBookCon")
    public String ToSingleBookCon(HttpServletRequest request, Model model, HttpSession session) {
        String hotlename = request.getParameter("hotlename");
        String roomprice = request.getParameter("roomprice");
        String roomType = request.getParameter("roomType");
        String users=session.getAttribute("users").toString();
        model.addAttribute("users",users);

        model.addAttribute("hotlename",hotlename);
        model.addAttribute("roomPrice",roomprice);
        model.addAttribute("roomType",roomType);
        return "SingleBook";
    }


}
